from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.ui import Console
from autogen_ext.models.openai import OpenAIChatCompletionClient
from autogen_core.models import UserMessage
from autogen_agentchat.messages import MultiModalMessage
from autogen_core import Image as AGImage
from autogen_agentchat.base import TaskResult
from autogen_agentchat.conditions import ExternalTermination, TextMentionTermination
from autogen_agentchat.teams import RoundRobinGroupChat
from autogen_core import CancellationToken
import PIL
from autogen_core import Image
from io import BytesIO
import asyncio
import requests
from typing import Literal
from pydantic import BaseModel


# Define a model client. You can use other model client that implements
# the `ChatCompletionClient` interface.


model_client = OpenAIChatCompletionClient(
    model="qwen-vl-max",
    api_key="sk-925b8bbb82424b74a8de940d2dc5a6ce",
    base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
    model_info={
        "vision": True,
        "function_calling": True,
        "json_output": False,
        "family": "unknown",
        "structured_output": True,
        "max_tokens": 8192,
        "top_p":0.8
    }
    # api_key="YOUR_API_KEY",
)

def increment_number(number: int) -> int:
    """Increment a number by 1."""
    return number + 1

agent = AssistantAgent(
    name="assistant",
    model_client=model_client,
    model_client_stream=False,
    tools=[increment_number],
    system_message="You are a helpful assistant. use the tools to increment the number"
)

termination = TextMentionTermination("stop")

team = RoundRobinGroupChat([agent], termination_condition=termination)


async def main():
    await Console(team.run_stream(task="increment the number from 5 to 10."))

asyncio.run(main())